﻿Imports System.ComponentModel
Imports System.Runtime.Serialization

''' <summary>
''' Base class which provides IsDirty status and an implementation of INotifyPropertyChanged
''' </summary>
''' <remarks></remarks>
''' <editHistory></editHistory>
<DataContract()> _
Public Class ItemBase
    Implements INotifyPropertyChanged

    Private _isDirty As Boolean

    ''' <summary>
    ''' Gets a valude indicating whether the object is dirty or not.
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    Public Overridable ReadOnly Property IsDirty() As Boolean
        Get
            Return _isDirty
        End Get
    End Property

    ''' <summary>
    ''' Marks the items as clean
    ''' </summary>
    ''' <remarks></remarks>
    Friend Overridable Sub MarkClean()

        'Mark the item as clean
        _isDirty = False

    End Sub

    ''' <summary>
    ''' Marks the item as dirty
    ''' </summary>
    ''' <param name="propertyName">The name of the property that changed.</param>
    ''' <remarks></remarks>
    Protected Sub MarkDirty(ByVal propertyName As String)
        MarkDirty()

        'Fire the event
        FirePropertyChanged(propertyName)
    End Sub

    ''' <summary>
    ''' Marks the item as dirty.
    ''' </summary>
    ''' <remarks></remarks>
    Protected Sub MarkDirty()

        'Mark the object as dirty.
        _isDirty = True

    End Sub

    ''' <summary>
    ''' Fires the property changed event
    ''' </summary>
    ''' <param name="propertyName"></param>
    ''' <remarks></remarks>
    Protected Sub FirePropertyChanged(ByVal propertyName As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
    End Sub

    Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
End Class
